﻿using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.DTO;
using mendian;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DXApplicationTangche.UC.生产计划.编排生产批.service
{
    public class 编排生产批Service
    {
        public static List<DTO生产批> get根据订单id查询生产批(List<String> orderIds)
        {
            return
                FunctionHelper.JsonDeserialization<List<DTO生产批>>(
                    RestCall.PostHttp(
                        URL.接口url + "/pmc/findWIPBatchByOrderId",
                        FunctionHelper.JsonSerialization(orderIds)
                    )
                );
        }
        public static List<DTO生产批> post初始化生产批(List<String> orderIds)
        {
            return
                FunctionHelper.JsonDeserialization<List<DTO生产批>>(
                    RestCall.PostHttp(
                        URL.接口url + "/pmc/initWIPBatch",
                        FunctionHelper.JsonSerialization(orderIds)
                        )
                );
        }
        public static Boolean get判断订单是否未排产(String orderId)
        {
            return
                FunctionHelper.JsonDeserialization<Boolean>(
                    RestCall.httpGetMethod(
                            URL.接口url + "/pmc/checkOrderNotScheduled?orderId=" + orderId
                            )
                    );
        }
        public static void post非批次管理情况下标记订单状态为已排产(String orderId)
        {
            RestCall.PostHttp(
                URL.接口url + "/pmc/orderScheduled",
                orderId
                    );
        }

        public static DTO生产批 post批次管理编排生产计划(String batchNo)
        {
            return
                FunctionHelper.JsonDeserialization<DTO生产批>(
                    RestCall.PostHttp(
                        URL.接口url + "/pmc/generateProductionPlan",
                        batchNo
                        )
                );
        }
        public static List<DTO生产批> post拆批(String batchNo, Double batchQuantiry)
        {
            return
                FunctionHelper.JsonDeserialization<List<DTO生产批>>(
                    RestCall.PostHttp(
                        URL.接口url + "/pmc/createNewBatch?batchNo=" + batchNo,
                        batchQuantiry.ToString()
                        )
                );
        }
        public static DTO生产批 post变更为加急状态(String batchNo)
        {
            return
                FunctionHelper.JsonDeserialization<DTO生产批>(
                    RestCall.PostHttp(
                        URL.接口url + "/pmc/saveWIPBatchToUrgent",
                        batchNo
                        )
                );
        }
        public static DTO生产批 post变更为不加急状态(String batchNo)
        {
            return
                FunctionHelper.JsonDeserialization<DTO生产批>(
                    RestCall.PostHttp(
                        URL.接口url + "/pmc/saveWIPBatchToNormal",
                        batchNo
                        )
                );
        }
        public static DTO生产批 get根据生产批查询生产信息(String batchNo)
        {
            return
                FunctionHelper.JsonDeserialization<DTO生产批>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/pmc/getWIPBatchByBatchNo?batchNo=" + batchNo
                        )
                );
        }
        public static DTO生产批 get根据成衣码查询生产信息(String barcode)
        {
            return
                FunctionHelper.JsonDeserialization<DTO生产批>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/garment/getOrderCommitDtoByBarcode?barcode=" + barcode
                        )
                );
        }
        /// <summary>
        /// 根据orderId查询生产批信息
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public static DTO生产批 findRecentWIPBatchByOrderId(String orderId)
        {
            return
                FunctionHelper.JsonDeserialization<DTO生产批>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/pmc/findRecentWIPBatchByOrderId?orderId=" + orderId
                        )
                    );
        }
        /// <summary>
        /// 根据batchNo查询生产批信息
        /// </summary>
        /// <param name="batchNo"></param>
        /// <returns></returns>
        public static DTO生产批 getWIPBatchByBatchNo(String batchNo)
        {
            return
                FunctionHelper.JsonDeserialization<DTO生产批>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/pmc/getWIPBatchByBatchNo?batchNo=" + batchNo
                        )
                    );
        }
        /// <summary>
        /// 根据批号查询生产批
        /// </summary>
        /// <param name="id"></param>
        /// <param name="batchNo"></param>
        /// <returns></returns>
        public static WIPPlanBatchDTO getWIPPlanBatchByBatchNo(String id, String batchNo)
        {
            return
                FunctionHelper.JsonDeserialization<WIPPlanBatchDTO>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/bom/getWIPPlanBatchByBatchNo?id=" + id + "&batchNo=" + batchNo
                        )
                    );
        }
        /// <summary>
        /// 保存工作计划
        /// </summary>
        /// <param name="mnemonic"></param>
        /// <param name="batchNo"></param>
        /// <param name="apsCode"></param>
        public static String saveBatchProjectWorkRecode(String mnemonic, String batchNo, String apsCode)
        {
            return
                RestCall.httpGetMethod(
                    URL.接口url + "/project/saveBatchProjectWorkRecode?mnemonic=" + mnemonic + "&batchNo=" + batchNo + "&apsCode=" + apsCode
            );
        }
        /// <summary>
        /// 计划执行
        /// </summary>
        /// <param name="mnemonic"></param>
        /// <param name="batchNo"></param>
        /// <param name="code"></param>
        /// <param name="content"></param>
        /// <param name="apsCode"></param>
        public static String saveBatchProjectRecode(String mnemonic, String batchNo, String code, String content, String apsCode)
        {
            return
                RestCall.httpGetMethod(
                    URL.接口url + "/project/saveBatchProjectRecode?mnemonic=" + mnemonic
                                + "&batchNo=" + batchNo
                                + "&code=" + code
                                + "&content=" + content
                                + "&apsCode=" + apsCode
            );
        }
        /// <summary>
        /// 生产计划按照批次编排并让审版变为已完成且记录审版执行
        /// </summary>
        /// <param name="mnemonic"></param>
        /// <param name="batchNo"></param>
        /// <param name="code"></param>
        /// <param name="apsCode"></param>
        /// <param name="content"></param>
        public static String generateProductionPlanAndSaveRecord(String mnemonic, String batchNo, String code, String apsCode, String content)
        {
            return
                RestCall.httpGetMethod(
                    URL.接口url + "/pmc/generateProductionPlanAndSaveRecord?mnemonic=" + mnemonic
                                + "&batchNo=" + batchNo
                                + "&code=" + code
                                + "&apsCode=" + apsCode
                                + "&content=" + content
            );
        }
        /// <summary>
        /// 取工序执行数量一览
        /// </summary>
        /// <returns></returns>
        public static List<ProcessOrderQueryDTO> getProcessExecuteView()
        {
            return
                FunctionHelper.JsonDeserialization<List<ProcessOrderQueryDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url1 + "/order_info/getProcessExecuteView"
                    )
                );
        }

        /// <summary>
        /// 成衣在制品记录
        /// </summary>
        /// <returns></returns>
        public static List<BarcodeWipRecordDTO> getBarcodeLogList()
        {
            return
                FunctionHelper.JsonDeserialization<List<BarcodeWipRecordDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url1 + "/order_info/getBarcodeLogList"
                    )
                );
        }

        /// <summary>
        /// 条码日志同步
        /// </summary>
        /// <param name="syncDate"></param>
        /// <returns></returns>
        public static String barcodeLogSync(String syncDate)
        {
            return
                RestCall.httpGetMethod(
                    URL.接口url1 + "/order_info/barcodeLogSync?syncDate=" + syncDate
                );
        }

        /// <summary>
        /// 每款出入库汇总
        /// </summary>
        /// <param name="syncDate"></param>
        /// <returns></returns>
        public static List<DouyinStockTitileDTO> getDouyinStockTitile(String salesDate)
        {
            return
                FunctionHelper.JsonDeserialization<List<DouyinStockTitileDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url1 + "/order_info/getDouyinStockTitile?salesDate=" + salesDate
                    )
                );
        }

        /// <summary>
        /// 查询面料对应生产批信息
        /// </summary>
        /// <param name="salesDate"></param>
        /// <returns></returns>
        public static List<DTO生产批> getWIPBatchByMaterialCode(String materialCode)
        {
            return
                FunctionHelper.JsonDeserialization<List<DTO生产批>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/pmc/getWIPBatchByMaterialCode?materialCode=" + materialCode
                    )
                );
        }
    }
    public class ApsConsts
    {
        public const String REVIEW_RECEIVE = "审版接收";
        public const String REVIEW_EXECUTE = "审版执行";
        public const String BROKEN_MATERIAL = "断料";
        public const String TAILORING = "裁剪";
        public ApsConsts()
        {

        }
    }

    public class DTO生产批
    {
        public String addressCity { get; set; }
        public String addressDetail { get; set; }
        public String addressDistrict { get; set; }
        public String addressId { get; set; }
        public String addressProvince { get; set; }
        public DateTime batchDate { get; set; }
        public String batchNo { get; set; }
        public Double batchQuantiry { get; set; }
        public String batchStatus { get; set; }
        public String composition { get; set; }
        public String customerCountId { get; set; }
        public String customerId { get; set; }
        public String customerName { get; set; }
        public String materialCode { get; set; }
        public String materialNameCn { get; set; }
        public String mobile { get; set; }
        public DateTime orderDate { get; set; }
        public String orderId { get; set; }
        public String orderNo { get; set; }
        public String refOrderId { get; set; }
        public String refOrderNo { get; set; }
        public String refStyleId { get; set; }
        public String styleFabricId { get; set; }
        public String styleId { get; set; }
        public String styleNameCn { get; set; }
        public String styleSizeCd { get; set; }
        public Boolean urgentFlg { get; set; }
        public String zipCode { get; set; }
        public DTO生产批()
        {

        }

    }
    public class WIPPlanBatchDTO
    {
        public String batchNo { get; set; }  //  生产批次号
        public DateTime batchDate { get; set; } //  生产批次开立时间
        public String batchStatus { get; set; } //  生产批状态 @See  top.toptimus.constValue.PMCLotStatus
        public Boolean urgentFlg { get; set; }  //  加急标识
        public Double batchQuantity { get; set; }   //  需求数量
        public Double wipQuantity { get; set; }   //  实际数量

        /**
         * 订单信息
         */
        public String orderId { get; set; }
        public String orderNo { get; set; } //  订单号
        public DateTime orderDate { get; set; } //  订单时间
        /**
         * 款式信息
         */
        public String styleId { get; set; }
        public String refStyleId { get; set; }  //  参考款id
        public String styleSizeCd { get; set; } //  尺码
        public String styleNameCn { get; set; } //  款式名称
        /**
         * 面料信息
         */
        public String styleFabricId { get; set; }//面料id
        public String materialNameCn { get; set; }//面料描述名称
        public String materialCode { get; set; }  //面料号
        public String composition { get; set; }//面料成分
        /**
         * 客户信息
         */
        public String customerId { get; set; }
        public String customerName { get; set; }
        public String mobile { get; set; }
        public String addressId { get; set; }
        public String addressProvince { get; set; }//省
        public String addressCity { get; set; }//市
        public String addressDistrict { get; set; }//区
        public String addressDetail { get; set; }//详细地址
        public String zipCode { get; set; }//邮编
        public String customerCountId { get; set; }//客户量体id
        /**
         * 客户返单信息
         */
        public String refOrderId { get; set; }  //  客户返单id
        public String refOrderNo { get; set; }  //  客户返单号
        public WIPPlanBatchDTO()
        {

        }
    }
    public class 套号生产批DTO
    {
        public String addressCity { get; set; }
        public String addressDetail { get; set; }
        public String addressDistrict { get; set; }
        public String addressId { get; set; }
        public String addressProvince { get; set; }
        public DateTime batchDate { get; set; }
        public String batchNo { get; set; }
        public Double batchQuantiry { get; set; }
        public String batchStatus { get; set; }
        public String composition { get; set; }
        public String customerCountId { get; set; }
        public String customerId { get; set; }
        public String customerName { get; set; }
        public String materialCode { get; set; }
        public String materialNameCn { get; set; }
        public String mobile { get; set; }
        public DateTime orderDate { get; set; }
        public String orderId { get; set; }
        public String orderNo { get; set; }
        public String refOrderId { get; set; }
        public String refOrderNo { get; set; }
        public String refStyleId { get; set; }
        public String styleFabricId { get; set; }
        public String styleId { get; set; }
        public String styleNameCn { get; set; }
        public String styleSizeCd { get; set; }
        public Boolean urgentFlg { get; set; }
        public String zipCode { get; set; }
        public String orderType { get; set; }
        public 套号生产批DTO(DTO生产批 dto生产批)
        {
            this.orderDate = dto生产批.orderDate;
            this.orderNo = dto生产批.orderNo;
            this.orderId = dto生产批.orderId;
            this.styleNameCn = dto生产批.styleNameCn;
            this.styleSizeCd = dto生产批.styleSizeCd;
            this.materialCode = dto生产批.materialCode;
            this.materialNameCn = dto生产批.materialNameCn;
            this.composition = dto生产批.composition;
            this.customerName = dto生产批.customerName;
            this.mobile = dto生产批.mobile;
            this.batchNo = dto生产批.batchNo;
            this.batchDate = dto生产批.batchDate;
            this.batchQuantiry = dto生产批.batchQuantiry;
            this.batchStatus = dto生产批.batchStatus;
            this.urgentFlg = dto生产批.urgentFlg;

            if ("凯丹店".Equals(customerName))
            {
                this.orderType = "门店补货";
            }
            else if (!String.IsNullOrEmpty(customerName) && customerName.Contains("春衫定制"))
            {
                this.orderType = "其他";
            }
            else
            {
                this.orderType = "客户套号";
            }
        }
    }
    public class ProcessOrderQueryDTO
    {
        public String orderId { get; set; }
        public String orderNo { get; set; }
        public DateTime orderDate { get; set; }
        public String styleCode { get; set; }
        public String styleNameCn { get; set; }
        public String materialCode { get; set; }
        public String materialName { get; set; }
        public String styleSizeCd { get; set; }
        public String shopName { get; set; }
        public Double salePrice { get; set; }   //  零售价，吊牌价
        public Double onlineSalePrice { get; set; } //  电商零售价
        //  度量值
        public int orderNumber { get; set; }    //  （1）每个订单的数量
        public int caijian { get; set; }    //  （2）每个订单已裁剪但是没打水洗的数
        public int shuixi { get; set; } //  （3）每个订单已经打印出的水洗数
        public int unCheck { get; set; }    //  （4）待检查的数量
        public int unFinishChek { get; set; }   //  （5）待成品检查数量
        public int unStockIn { get; set; }  //  （6）已完成质检未入库数量
        public int stockIn { get; set; }    //  （7）已入库数量 ——入库数量
        public ProcessOrderQueryDTO()
        {

        }
    }

    public class BarcodeWipRecordDTO
    {
        public String barcode { get; set; }
        public DateTime orderDate { get; set; }    //	订单日期
        //  '半成品检查', '成品检查', '钉锁', '手缝'
        public DateTime semiCheck { get; set; }  //  半成品检查
        public DateTime finishCheck { get; set; }    //  成品检查
        public DateTime dingsuo { get; set; }    //  钉锁
        public DateTime shoufeng { get; set; }    //  手缝
        public String styleNameCn { get; set; }   //	款式
        public String materialCode { get; set; }    //	面料
        public String styleSizeCd { get; set; }    //	尺码
        public String orderId { get; set; }    //	生产订单id

        public BarcodeWipRecordDTO()
        {

        }
    }
    public class DouyinStockTitileDTO
    {
        public String styleCode { get; set; }
        public String fabricCode { get; set; }
        public String styleSizeCd { get; set; }
        public List<DouyinStockDetailDTO> stockInDetails { get; set; } = new List<DouyinStockDetailDTO>(); //  入库汇总
        public List<DouyinStockDetailDTO> stockOutDetails { get; set; } = new List<DouyinStockDetailDTO>();//  出库汇总
        public int stockInTotal { get; set; }   //  入库总数
        public int stockOutTotal { get; set; }   //  出库总数
        public DouyinStockTitileDTO()
        {

        }
    }

    public class DouyinStockDetailDTO
    {
        public String inoutType { get; set; }
        public String storeId { get; set; }
        public String storeName { get; set; }
        public int barcodeCount { get; set; }
        public DouyinStockDetailDTO()
        {

        }
    }
}
